package com.deadmosquitogames.notifications;

import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.os.Build;
import androidx.core.app.NotificationCompat;
import androidx.core.app.TaskStackBuilder;
import androidx.vectordrawable.graphics.drawable.PathInterpolatorCompat;

public class GoodiesNotificationManager extends BroadcastReceiver {
    private static final String BUNDLE = "bundle";
    private static final String COLOR = "color";

    /* renamed from: ID */
    private static final String f2798ID = "id";
    private static final String LARGE_ICON = "l_icon";
    private static final String LIGHTS = "lights";
    private static final String MESSAGE = "message";
    private static final String SMALL_ICON = "s_icon";
    private static final String SOUND = "sound";
    private static final String TICKER = "ticker";
    private static final String TITLE = "title";
    private static final String VIBRATE = "vibrate";

    public static void setNotification(Context context, int i, long j, String str, String str2, String str3, int i2, int i3, int i4, String str4, String str5, int i5, String str6) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(NotificationCompat.CATEGORY_ALARM);
        Intent intent = new Intent(context, GoodiesNotificationManager.class);
        intent.putExtra(TICKER, str3);
        intent.putExtra("title", str);
        intent.putExtra("message", str2);
        intent.putExtra("id", i);
        intent.putExtra("color", i5);
        boolean z = true;
        intent.putExtra(SOUND, i2 == 1);
        intent.putExtra(VIBRATE, i3 == 1);
        if (i4 != 1) {
            z = false;
        }
        intent.putExtra(LIGHTS, z);
        intent.putExtra(LARGE_ICON, str4);
        intent.putExtra(SMALL_ICON, str5);
        intent.putExtra(BUNDLE, str6);
        PendingIntent broadcast = PendingIntent.getBroadcast(context, i, intent, 134217728);
        if (Build.VERSION.SDK_INT >= 23) {
            alarmManager.setExact(0, System.currentTimeMillis() + j, broadcast);
        } else {
            alarmManager.set(0, System.currentTimeMillis() + j, broadcast);
        }
    }

    public static void setRepeatingNotification(Context context, int i, long j, String str, String str2, String str3, long j2, int i2, int i3, int i4, String str4, String str5, int i5, String str6) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(NotificationCompat.CATEGORY_ALARM);
        Intent intent = new Intent(context, GoodiesNotificationManager.class);
        intent.putExtra(TICKER, str3);
        intent.putExtra("title", str);
        intent.putExtra("message", str2);
        intent.putExtra("id", i);
        intent.putExtra("color", i5);
        boolean z = false;
        intent.putExtra(SOUND, i2 == 1);
        intent.putExtra(VIBRATE, i3 == 1);
        if (i4 == 1) {
            z = true;
        }
        intent.putExtra(LIGHTS, z);
        intent.putExtra(LARGE_ICON, str4);
        intent.putExtra(SMALL_ICON, str5);
        intent.putExtra(BUNDLE, str6);
        alarmManager.setRepeating(0, System.currentTimeMillis() + j, j2, PendingIntent.getBroadcast(context, i, intent, 134217728));
    }

    public static void cancelNotification(Context context, int i) {
        ((AlarmManager) context.getSystemService(NotificationCompat.CATEGORY_ALARM)).cancel(PendingIntent.getBroadcast(context, i, new Intent(context, GoodiesNotificationManager.class), 0));
    }

    private static String getApplicationName(Context context) {
        ApplicationInfo applicationInfo = context.getApplicationInfo();
        int i = applicationInfo.labelRes;
        return i == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(i);
    }

    @Override // android.content.BroadcastReceiver
    public void onReceive(Context context, Intent intent) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        String stringExtra = intent.getStringExtra(TICKER);
        String stringExtra2 = intent.getStringExtra("title");
        String stringExtra3 = intent.getStringExtra("message");
        String stringExtra4 = intent.getStringExtra(SMALL_ICON);
        String stringExtra5 = intent.getStringExtra(LARGE_ICON);
        int intExtra = intent.getIntExtra("color", 0);
        String stringExtra6 = intent.getStringExtra(BUNDLE);
        Boolean valueOf = Boolean.valueOf(intent.getBooleanExtra(SOUND, false));
        Boolean valueOf2 = Boolean.valueOf(intent.getBooleanExtra(VIBRATE, false));
        Boolean valueOf3 = Boolean.valueOf(intent.getBooleanExtra(LIGHTS, false));
        int intExtra2 = intent.getIntExtra("id", 0);
        Resources resources = context.getResources();
        Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(stringExtra6);
        TaskStackBuilder.create(context).addNextIntent(launchIntentForPackage);
        PendingIntent activity = PendingIntent.getActivity(context, 0, launchIntentForPackage, 134217728);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setContentIntent(activity).setAutoCancel(true).setContentTitle(stringExtra2).setContentText(stringExtra3);
        if (Build.VERSION.SDK_INT >= 21) {
            builder.setColor(intExtra);
        }
        if (stringExtra != null && stringExtra.length() > 0) {
            builder.setTicker(stringExtra);
        }
        if (stringExtra4 != null && stringExtra4.length() > 0) {
            builder.setSmallIcon(resources.getIdentifier(stringExtra4, "drawable", context.getPackageName()));
        }
        if (stringExtra5 != null && stringExtra5.length() > 0) {
            builder.setLargeIcon(BitmapFactory.decodeResource(resources, resources.getIdentifier(stringExtra5, "drawable", context.getPackageName())));
        }
        if (valueOf.booleanValue()) {
            builder.setSound(RingtoneManager.getDefaultUri(2));
        }
        if (valueOf2.booleanValue()) {
            builder.setVibrate(new long[]{1000, 1000});
        }
        if (valueOf3.booleanValue()) {
            builder.setLights(-16711936, PathInterpolatorCompat.MAX_NUM_POINTS, PathInterpolatorCompat.MAX_NUM_POINTS);
        }
        if (Build.VERSION.SDK_INT >= 26) {
            notificationManager.createNotificationChannel(new NotificationChannel("default", getApplicationName(context), 2));
            builder.setChannelId("default");
        }
        notificationManager.notify(intExtra2, builder.build());
    }
}